import { getList, getListMusic, getsingleMusic, getSingleCommentApi, getMusicURLApi } from '../api/jxx'
// import { getLyrics } from '../api/zsj'
import { hotRequest, searchRequest } from '../api/mxx'
import { getReList, getComment } from '../api/cj'


const actionCreator = (type, payload) => ({ type, payload })
//获取榜单
export const getMusicList = () => dispatch => {
    //发送请求
    getList()
        .then(res => {
            // console.log(res.list)
            dispatch(actionCreator('LIST', res.list))
        });
}
export const getHot = () => dispatch => {
    hotRequest()
        .then(res => {
            // console.log(res.result.hots);
            // 获取到hot数据，并传递给Reducer
            dispatch(actionCreator('GET_HOT', res.result.hots))
        })
}
export const getSearch = (msg) => dispatch => {
    searchRequest(msg)
        .then(res => {
            // console.log(res.result.songs);
            // 获取到search数据，并传递给Reducer
            dispatch(actionCreator('GET_SEARCH', res.result.songs))
        })
}

// 获取榜单下的歌曲
export const getMusic = (id) => dispatch => {
    // console.log(id)
    //发送请求
    getListMusic(id)
        .then(res => {
            // console.log(res)
            dispatch(actionCreator('LIST_MUSIC', res.playlist.tracks))
            //设置播放歌单列表
            dispatch(actionCreator('PLAY_MUSIC_LIST', res.playlist.tracks))
        })
}
//根据id获取单曲
export const getsinglesons = (id) => dispatch => {
    getsingleMusic(id)
        .then(res => {
            dispatch(actionCreator('PLAY_MUSIC_LIST', res.songs))
        })
}

// 更改当前播放器状态
export const playOrPause = (status) => dispatch => {
    dispatch(actionCreator('PLAYRORPAUSE', status))
}

// 获取音乐id
export const getMusicId = (id = 1369798757) => dispatch => {
    dispatch(actionCreator('MUSIC_ID', id))
}

//改变showplaylist
export const changeShowplaylist = (msg) => dispatch => {
    dispatch(actionCreator('SHOW_PLAY_LIST', msg))
}


//陈锦歌单列表
export const getReMusicList = (url) => dispatch => {
    //发送歌单列表请求
    getReList(url)
        .then(res => {
            dispatch(actionCreator('RE_LIST', res.playlist))
        })
}
export const getReMusicComment = (url) => dispatch => {
    //发送歌单评论请求
    getComment(url)
        .then(res => {
            dispatch(actionCreator('COMMENT', res.comments))
        })
}
//当前播放音乐的index
export const getNowindex = (index) => dispatch => {
    dispatch(actionCreator('LIST_MUSIC_INDEX', index))
}
//控制播放页面是否出现
export const changeShowplay = (msg) => dispatch => {
    dispatch(actionCreator('SHOW_PLAY', msg))
}
// 滑动进度条设置时间
export const setcurrentTime = second => dispatch => {
    dispatch(actionCreator('CURRENT_TIME', second))
}

// 获取单曲音乐评论
export const getSingleComment = id => dispatch => {
    getSingleCommentApi(id)
        .then(res => {
            // console.log(res)
            dispatch(actionCreator("GET_SLNGLE_COMMENTS", res.hotComments))
        })
}
//改变播放模式
export const changeCycle = msg => dispatch => {
    dispatch(actionCreator('CHANGE_CYCLE', msg))
}
//获取歌单或歌曲id
export const setId = obj => dispatch => {
    dispatch(actionCreator('TYPE_ID', obj))
}
//获取当前音乐已经播放的时长
export const getTimenow = msg => dispatch => {
    dispatch(actionCreator('TIMING', msg))
}
//清空当前以播放的时长
export const clearTimenow = () => dispatch => {
    dispatch(actionCreator('CLEAR_TIMING', 0))
}
//获取当前播放音乐的url
export const getMusicurl = (id) => dispatch => {
    //发送歌单评论请求
    getMusicURLApi(id)
        .then(res => {
            dispatch(actionCreator('MUSIC_URL', res.data[0].url))
        })
}

// 设置返回按钮跟随的文字信息
export const setReturnMsg = msg => dispatch => {
    dispatch(actionCreator("SET_MSG",msg))
}